package com.od.controller;

import com.od.entity.Work;
import com.od.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("work")
@CrossOrigin
public class WorkController {
    @Autowired
    private WorkService workService;

    @RequestMapping("getWorkById")
    @ResponseBody
    public List<Work> getWorkById(int workResume) {
        return workService.getWorkById(workResume);
    }

    @RequestMapping("addWork")
    @ResponseBody
    public int addWork(@RequestBody Work work) {
        System.out.println(work);
        return workService.addWork(work);
    }

    @RequestMapping("updateWorkById")
    @ResponseBody
    public int updateWorkBySeekerId(@RequestBody Work work) {
        System.out.println(work);
        return workService.updateWorkById(work);
    }

    @RequestMapping("deleteWorkById")
    @ResponseBody
    public int deleteWorkById(@RequestBody Map<String, Integer> workData) {
        int workId = workData.get("workId");
        return workService.deleteWorkById(workId);
    }

}
